/**
 * Created by blazecrystal on 2017/3/13.
 */

$('[data-toggle="tooltip"]').tooltip();

$("[name='addException']").click(function() {
    $(this).parent().parent().append(createContainer().append(createTypeSelect()).append(createAttrNameInput()).append(createAttrValueInput()).append(createRegexEn()).append(createDeleteBtn()));
    $('[data-toggle="tooltip"]').tooltip();
});
function createContainer() {
    return $("<div/>").addClass("form-inline").css("padding-bottom", "5px");
}
function createTypeSelect() {
    var typeSelect = $("<select/>").attr("name", "emtType").addClass("form-control");
    typeSelect.append(createOption(0, "输入框<input type=\"text\"/>"));
    typeSelect.append(createOption(1, "复选框<input type=\"checkbox\"/>"));
    typeSelect.append(createOption(2, "单选框<input type=\"radio\"/>"));
    typeSelect.append(createOption(3, "下拉列表（包括单选和多选）<select/>"));
    typeSelect.append(createOption(4, "文本域<textarea/>"));
    return typeSelect;
}
function createOption(val, label) {
    return $("<option/>").attr("value", val).text(label);
}
function createAttrNameInput() {
    return $("<div/>").addClass("form-group").append($("<input/>").attr("type", "text").addClass("form-control").attr("name", "attrName").attr("placeholder", "属性名称，空则匹配所有")).css("padding-left", "5px");
}
function createAttrValueInput() {
    return $("<div/>").addClass("form-group").append($("<input/>").attr("type", "text").addClass("form-control").attr("name", "attrValue").attr("placeholder", "属性值")).css("padding-left", "5px");
}
function createRegexEn() {
    return $("<div/>").addClass("checkbox").append($("<label/>").append($("<input/>").attr("type", "checkbox").attr("name", "regexEn")).append("&nbsp;正则")).css("padding-left", "5px");
}
function createDeleteBtn() {
    return $("<div/>").addClass("form-group").append("&nbsp;&nbsp;&nbsp;&nbsp;").append($("<button/>").attr("type", "button").addClass("btn").addClass("btn-danger").addClass("btn-sm").attr("name", "delException").attr("data-toggle", "tooltip").attr("data-placement", "top").attr("title", "点击按钮删除此项设置").append($("<span/>").addClass("fa").addClass("fa-times")).click(function() {
        $(this).parent().parent().remove();
    })).css("padding-left", "5px");
}